        //封装一个cache类
        class Cache
        {
            constructor(isLocal=true)
            {
                this.storage = isLocal?localStorage:sessionStorage;
            }

            setCache(key,value)
            {
                //判断value值是否非空
                if(!value)
                {
                    throw Error("value 必须有值");
                    return;
                }

                //给key设置值：为了传入对象的情况可以使用json方法进行转化
                this.storage.setItem(key,JSON.stringify(value));
            }

            getCache(key)
            {
               const result = this.storage.getItem(key);
               if(result)
               {
                  return JSON.parse(result);
               }
            }

            removeCache(key)
            {
                this.storage.removeItem(key);
            }

            clear()
            {
                this.storage.clear();
            }
}
        
let localCache = new Cache();
let sessionCache = new Cache(false);
